package com.aa.autoanswer;


import com.aa.Common;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;

public class AutoAnswerReceiver extends BroadcastReceiver {
private String TAG = "AutoAnswerReceiver";

	@Override
	public void onReceive(Context arg0, Intent arg1) {
		Log.i(TAG, "onReceive");
		
		
		String _Sate = arg1.getStringExtra("sate");
		Log.i(TAG, "state = " + _Sate);
		Log.i(TAG, "getCallState" + ((TelephonyManager)arg0.getSystemService("phone")).getCallState());
	
		int _sate = ((TelephonyManager)arg0.getSystemService("phone")).getCallState();
		
		//arg0.startService(new Intent(arg0, AutoAnswerIntentService.class));
		if (Common.iShowAutoAnswer) {
			Log.i(TAG, " auto answer");
			if (_sate == 1) {			
//				if (Common.iAutoAnswerFlag == 1) {
//					arg0.startService(new Intent(arg0, AutoAnswerIntentService.class));
//					Common.iAutoAnswerFlag = 2;
//				}
				arg0.startService(new Intent(arg0, AutoAnswerIntentService.class));
				Common.iShowAutoAnswer = false;
				Common.iIsEndCallUI = true;
			}
		}					
	}
}
